package com.jcl.elasticsearch.core.utils;

import com.jcl.core.constants.RedisConstant;
import com.jcl.core.model.RedisChannelAccount;
import com.jcl.elasticsearch.core.redis.RedisCache;

/**
 * @ClassName RedisCacheUtils
 * @Description TODO
 * @Author yyliu
 * @Date 2018/11/20 9:21
 * @Version 1.0
 **/
public class RedisCacheUtils {

    public static RedisChannelAccount getChanelAccount(String channelType, String corpCode){

        String key = RedisConstant.KEY_CHANNEL_ACCOUNT + RedisConstant.REDIS_SPLIT_KEY + channelType;

        return RedisCache.getMapField(key, corpCode, RedisChannelAccount.class);
    }

    public static void addChanelAccount(RedisChannelAccount account){
        String key = RedisConstant.KEY_CHANNEL_ACCOUNT + RedisConstant.REDIS_SPLIT_KEY + account.getSiteCode();

        String field = account.getCorpCode();
        RedisCache.addMap(key, field, account);
        // 添加队列
        addChanelAccountCorpCode(account.getSiteCode(), field);
    }

    public static Object getChanelAccountCorpCode(String channelType){
        String key = RedisConstant.KEY_CHANNEL_ACCOUNT_CORP
                + RedisConstant.REDIS_SPLIT_KEY + channelType;

        return RedisCache.lpop(key);
    }

    public static void addChanelAccountCorpCode(String channelType, String corpCode){
        String key = RedisConstant.KEY_CHANNEL_ACCOUNT_CORP
                + RedisConstant.REDIS_SPLIT_KEY + channelType;

        RedisCache.rpush(key, corpCode);
    }


}
